package com.chdwmp.product.controller;

import com.chdwmp.product.bean.CommonResponse;
import com.chdwmp.product.bean.app.Activation;
import com.chdwmp.product.bean.app.EquipmentUpdate;
import com.chdwmp.product.bean.backend.AgentVo;
import com.chdwmp.product.bean.backend.ProductAgentSearchVo;
import com.chdwmp.product.bean.backend.ProductStatisticsVo;
import com.chdwmp.product.bean.params.AgentListSearch;
import com.chdwmp.product.service.AgentService;
import com.chdwmp.product.service.AppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: LLL
 * @Date: 2021/3/13 21:10
 * @Description: app交互controller
 */
@Api(description = "供应商模块", tags = {"供应商模块接口控制层"})
@RequestMapping("/agent")
@RestController
public class AgentController {

    @Autowired
    AgentService agentService;


    /**
     * 新增或修改 供应商
     * @param agentVo
     * @return
     * @throws Exception
     */
    @PostMapping("/activation")
    @ApiOperation(value = "新增或修改供应商", notes = "新增或修改 供应商",httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse saveOrUpdateAgent(@RequestBody AgentVo agentVo) throws Exception {
        agentService.saveOrUpdateAgent(agentVo);
        return new CommonResponse();
    }

    @PostMapping("/add/for/app/v2")
    @ApiOperation(value = "新增供应商", notes = "新增供应商",httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse<AgentVo> addAgentForApp(@RequestBody AgentVo agentVo) throws Exception {
        return new CommonResponse(agentService.addAgentForApp(agentVo));
    }

    /**
     * 删除供应商
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/deleteAgent/{id}")
    @ApiOperation(value = "删除供应商", notes = "删除供应商",httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse deleteAgent(@PathVariable String id) throws Exception {
        agentService.deleteAgent(id);
        return new CommonResponse();
    }

    /**
     * 获取供应商列表
     * @param search
     * @return
     * @throws Exception
     */
    @PostMapping("/getAgentList")
    @ApiOperation(value = "获取供应商列表", notes = "获取供应商列表",httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse<AgentVo> getAgentList(@RequestBody AgentListSearch search) throws Exception {
        return new CommonResponse (agentService.getAgentList(search));
    }


    /**
     * 获取供应商购买产品列表
     * @param search
     * @return
     * @throws Exception
     */
    @PostMapping("/getAgentBuyProducts")
    @ApiOperation(value = "获取供应商购买产品列表", notes = "获取供应商购买产品列表",httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse<AgentVo> getAgentBuyProducts(@RequestBody AgentListSearch search) throws Exception {
        return new CommonResponse (agentService.getAgentBuyProducts(search));
    }

    @PostMapping("/getProductAgentStatistics")
    @ApiOperation(value = "统计供应商购买产品", notes = "统计供应商购买产品",httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse<ProductStatisticsVo> getProductAgentStatistics(@RequestBody ProductAgentSearchVo productAgentSearchVo) throws Exception {
        return new CommonResponse (agentService.getProductAgentStatistics(productAgentSearchVo));
    }

    @GetMapping("/get/info/{imei}")
    @ApiOperation(value = "根据imei获取供应商信息", notes = "根据imei获取供应商信息",httpMethod = "GET", response = CommonResponse.class)
    public CommonResponse<AgentVo> getAgentInfo(@PathVariable String imei) throws Exception {
        return new CommonResponse (agentService.getAgentInfo(imei));
    }



}
